package com.ruoyi.web.controller.ziran;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ziran.domain.ZrConsult;
import com.ruoyi.ziran.service.IZrConsultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咨询Controller
 * 
 * @author ruoyi
 * @date 2024-11-24
 */
@Controller
@RequestMapping("/ziran/consult")
public class ZrConsultController extends BaseController
{
    private String prefix = "ziran/consult";

    @Autowired
    private IZrConsultService zrConsultService;

    //@RequiresPermissions("ziran:consult:view")
    @GetMapping()
    public String consult()
    {
        return prefix + "/consult";
    }

    /**
     * 查询咨询列表
     */
    //@RequiresPermissions("ziran:consult:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZrConsult zrConsult)
    {
        startPage();
        List<ZrConsult> list = zrConsultService.selectList(zrConsult);
        return getDataTable(list);
    }

    /**
     * 导出咨询列表
     */
    //@RequiresPermissions("ziran:consult:export")
    @Log(title = "咨询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZrConsult zrConsult)
    {
        List<ZrConsult> list = zrConsultService.selectList(zrConsult);
        ExcelUtil<ZrConsult> util = new ExcelUtil<ZrConsult>(ZrConsult.class);
        return util.exportExcel(list, "咨询数据");
    }

    /**
     * 新增咨询
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存咨询
     */
    //@RequiresPermissions("ziran:consult:add")
    @Log(title = "咨询", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZrConsult zrConsult)
    {
        return toAjax(zrConsultService.insertZrConsult(zrConsult));
    }

    /**
     * 修改咨询
     */
    //@RequiresPermissions("ziran:consult:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZrConsult zrConsult = zrConsultService.getInfoById(id);
        mmap.put("zrConsult", zrConsult);
        return prefix + "/edit";
    }

    /**
     * 修改保存咨询
     */
    //@RequiresPermissions("ziran:consult:edit")
    @Log(title = "咨询", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZrConsult zrConsult)
    {
        return toAjax(zrConsultService.updateZrConsult(zrConsult));
    }

    /**
     * 删除咨询
     */
    //@RequiresPermissions("ziran:consult:remove")
    @Log(title = "咨询", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zrConsultService.deleteZrConsultByIds(ids));
    }
}
